package com.mirce.config;

import com.mirce.mapper.userMapper;
import com.mirce.pojo.User;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

public class userRealm extends AuthorizingRealm {



    @Autowired
    userMapper usermapper;

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {

        //System.out.println("->执行了授权方法");
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {



       // System.out.println("->执行了验证方法");
           UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
           String username = token.getUsername();
           User userDao =usermapper.queryUser(username);
           //System.out.println(username);
           return new SimpleAuthenticationInfo(username,userDao.getPassword(),"");

    }

}
